package com.weimin.ghostdrop.controller;

import com.weimin.ghostdrop.entity.Links;
import com.weimin.ghostdrop.entity.dto.LinksDTO;
import com.weimin.ghostdrop.service.LinksService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : huiMing
 * Date : 2025年10月11日 10:54
 * @version V1.0
 */
@RestController
@RequestMapping("/link")
@RequiredArgsConstructor
public class LinksController {
    private final LinksService linksService;

    // 新增/更新：根据 softwareId 覆盖写入 links
    @PostMapping("/{softwareId}")
    public Boolean saveOrUpdate(@PathVariable("softwareId") Integer softwareId,
                                @Validated @RequestBody LinksDTO dto) {
        linksService.saveOrUpdateBySid(softwareId, dto);
        return true;
    }

    // 根据 softwareId 查询全部链接
    @GetMapping("/software/{softwareId}")
    public Links getBySoftware(@PathVariable("softwareId") Integer softwareId) {
        return linksService.getBySid(softwareId);
    }
}
